/*
	This file is part of AVRCppLib.

    AVRCppLib is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    AVRCppLib is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with AVRCppLib.  If not, see <http://www.gnu.org/licenses/>.

    Copyright (C) Maxime Lemonnier 2007-2011
 */

#ifndef USIHardware_H_
#define USIHardware_H_
#include "../../Utils/CppExtensions.h"
#include "../../Utils/BitManipulation.h"


namespace Coms
{

namespace USI
{

namespace ClockSources
{

enum ClockSource
{
	SOFTWARE = 0x00,
	TIMER_OC_PIN = 0x01,
	EXTERNAL_POSITIVE_EDGE = 0x02,
	EXTERNAL_NEGATIVE_EDGE = 0x03,
};

}



using ClockSources::ClockSource;


class USIHardware
{
public:
	static USIHardware * getUSIHardware();
	virtual ~USIHardware();

	inline bool readStartConditionInterruptFlag() FORCE_INLINE;
	inline void clearStartConditionInterruptFlag() FORCE_INLINE;
	inline void enableStartConditionInterrupts() FORCE_INLINE;
	inline void disableStartConditionInterrupts() FORCE_INLINE;

	inline bool readCounterOverflowInterruptFlag() FORCE_INLINE;
	inline void clearCounterOverflowInterruptFlag() FORCE_INLINE;
	inline void enableCounterOverflowInterrupts() FORCE_INLINE;
	inline void disableCounterOverflowInterrupts() FORCE_INLINE;

	inline bool readStopConditionFlag() FORCE_INLINE;
	inline void clearStopConditionFlag() FORCE_INLINE;

	inline bool readWriteCollisionFlag() FORCE_INLINE;

	inline uint8_t readCounterValue() FORCE_INLINE;

	inline void disable() FORCE_INLINE;
	inline void enableInSPIMode() FORCE_INLINE;
	inline void enableInI2CMode() FORCE_INLINE;

	inline void setClockSourceMode(ClockSource clockSource) FORCE_INLINE;

	inline void setClockStrobe() FORCE_INLINE;
	inline void clearClockStrobe() FORCE_INLINE;

	inline void toggleClock() FORCE_INLINE;

	inline uint8_t readByte() FORCE_INLINE;

	inline void writeByte(uint8_t byte) FORCE_INLINE;



protected:

	USIHardware(uint8_t callbackVectorNumber, IOAddress usidr, IOAddress usibr, IOAddress usisr, IOAddress usicr);


	uint8_t callbackVectorNumber;
	IOAddress usidr;
	IOAddress usibr;
	IOAddress usisr;
	IOAddress usicr;

};

#include "USIHardware-definition.h"

}

}

#endif /* USIHardware_H_ */
